﻿using System.CodeDom.Compiler;
using Anmlz.Model.Entities;
using Anmlz.Model.Model;
using Anmlz.Services;

namespace Anmlz.Data.ModelFactory
{
    public partial class ModelFactory
    {
        public BreedModel Create(Breed entity)
        {
            var model = new BreedModel
                            {
                                Id = entity.Id,
                                CreatureTypeId = entity.CreatureTypeId,
                                BreedGroupId = entity.BreedGroupId,
                                CreatureSizeTypeId = entity.CreatureSizeTypeId,
                                WeightMaleMin = entity.WeightMaleMin,
                                WeightMaleMax = entity.WeightMaleMax,
                                HeightMaleMin = entity.HeightMaleMin,
                                HeightMaleMax = entity.HeightMaleMax,
                                WeightFemaleMin = entity.WeightFemaleMin,
                                WeightFemaleMax = entity.WeightFemaleMax,
                                HeightFemaleMin = entity.HeightFemaleMin,
                                HeightFemaleMax = entity.HeightFemaleMax,
                                LifeSpanMin = entity.LifeSpanMin,
                                LifeSpanMax = entity.LifeSpanMax
                            };

            switch (_languageService.GetCurrentLanguage())
            {
                case CultureNames.English:
                    model.Name = entity.NameEn;
                    model.OtherNames = entity.OtherNamesEn;
                    model.Description = entity.DescriptionEn;
                    break;
                case CultureNames.Russian:
                    model.Name = entity.NameRu;
                    model.OtherNames = entity.NameRu;
                    model.Description = entity.DescriptionRu;
                    break;
            }
            return model;
        }

        public Breed Parse(BreedModel model, bool creation = false)
        {
            Breed entity = null;
            if (!creation)
            {
                entity = _unitOfWork.Breeds.GetById(model.Id);
            }
            if (entity == null)
            {
                entity = new Breed();
            }

            entity.Id = model.Id;
            entity.CreatureTypeId = model.CreatureTypeId;
            entity.BreedGroupId = model.BreedGroupId;
            entity.CreatureSizeTypeId = model.CreatureSizeTypeId;
            entity.WeightMaleMin = model.WeightMaleMin;
            entity.WeightMaleMax = model.WeightMaleMax;
            entity.HeightMaleMin = model.HeightMaleMin;
            entity.HeightMaleMax = model.HeightMaleMax;
            entity.WeightFemaleMin = model.WeightFemaleMin;
            entity.WeightFemaleMax = model.WeightFemaleMax;
            entity.HeightFemaleMin = model.HeightFemaleMin;
            entity.HeightFemaleMax = model.HeightFemaleMax;
            entity.LifeSpanMin = model.LifeSpanMin;
            entity.LifeSpanMax = model.LifeSpanMax;
            entity.OriginCountries = model.OriginCountries;

            switch (_languageService.GetCurrentLanguage())
            {
                case CultureNames.English:
                    entity.NameEn = model.Name;
                    entity.OtherNamesEn = model.OtherNames;
                    entity.DescriptionEn = model.Description;
                    break;
                case CultureNames.Russian:
                    entity.NameRu = model.Name;
                    entity.OtherNamesRu = model.Name;
                    entity.DescriptionRu = model.Description;
                    break;
            }

            return entity;
        }
    }
}